
package com.jf.cloud.combo.listener;

import com.jf.cloud.api.product.feign.ShopCartFeignClient;
import com.jf.cloud.combo.bo.ComboSkuStatusChangeNotifyBO;
import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zz
 * @date 2022/8/30 13:36
 * 套餐商品sku项状态变为删除或者失效时移除用户购物车商品
 */
@Component
@RocketMQMessageListener(topic = RocketMqConstant.COMBO_SKU_STATUS_TOPIC,consumerGroup = RocketMqConstant.COMBO_SKU_STATUS_TOPIC)
public class ComboSpuSkuListener implements RocketMQListener<ComboSkuStatusChangeNotifyBO> {
    @Autowired
    private ShopCartFeignClient shopCartFeignClient;

    @Override
    public void onMessage(ComboSkuStatusChangeNotifyBO comboSkuStatusChangeNotifyBO) {
        Long comboId = comboSkuStatusChangeNotifyBO.getComboId();
        List<Long> skuList = comboSkuStatusChangeNotifyBO.getSkuList();
        if (skuList.size() != 0){
            shopCartFeignClient.deleteCartByComboIdAndSkuIdS(comboId,skuList);
        }
    }
}
